package br.com.listadecompras.utils;

import java.util.LinkedList;

import br.com.listadecompras.activities.R;
import br.com.listadecompras.model.Item;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemArrayAdapter extends ArrayAdapter<Item> {
	
	//private LinkedList<Item> itens;
	private int viewLayoutId;
	
	public ItemArrayAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		this.viewLayoutId = textViewResourceId;
	}


	public ItemArrayAdapter(Context context, int textViewResourceId, LinkedList<Item> itens) {
		super(context, textViewResourceId, itens);
		this.viewLayoutId = textViewResourceId;
		
		//this.itens = itens;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Item item = getItem(position);
		
		if (convertView == null) {
			
			LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(this.viewLayoutId, null);
			
		} 
		
		if (item != null) {
		
			TextView txtNome = (TextView)convertView.findViewById(R.id.text);
			txtNome.setText(item.getNome());
		}
		return convertView;
	}
	
}
